package com.box.app.arithmetic

import kotlinx.cinterop.refTo
import kotlinx.cinterop.toKString
import platform.posix.memcpy
import platform.posix.sprintf

internal actual fun Number.format(digit: Int): Any {
    val buffer = ByteArray(64)
    val result = sprintf(buffer.refTo(0), "%.($digit)f", toDouble())
    val resultBytes = ByteArray(result)
    memcpy(resultBytes.refTo(0), buffer.refTo(0), result.toULong())
    return resultBytes.toKString()
}